import {
  ResPage,
  Dict,
  Role,
  Menu,
  User,
  File,
  Area,
  Setting,
  Question,
  Audit,
  Answer,
  Commit,
  Lesson,
  Country
} from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 字典管理模块
 */

// 添加字典
export const addDictList = (params: Dict.ReqDictParams) => {
  return http.post<ResPage<Dict.ResDictList>>(PORT1 + `/param/add`, params);
};

// 添加字典
export const editDictList = (params: Dict.ReqDictParams) => {
  return http.post<ResPage<Dict.ResDictList>>(PORT1 + `/param/edit`, params);
};

// 删除字典
export const delDictList = (params: Dict.ReqDictParams) => {
  return http.get<ResPage<Dict.ResDictList>>(PORT1 + `/param/delete`, params);
};

// 查询一级目录字典
export const getDictList = () => {
  return http.get<ResPage<Dict.ResDictList>>(PORT1 + `/param/getParamRoot`, {}, { noLoading: true });
};

// 根据父ID查询参数
export const getDict = (params: Dict.ReqDictParams) => {
  return http.get<ResPage<Dict.ResDictList>>(PORT1 + `/param/getParamByParentId`, params, { noLoading: true });
};

// 根据子ID查询树链路
export const getParamTreeByChildId = (params: Dict.ReqDictParams) => {
  return http.get<ResPage<Dict.ResDictList>>(PORT1 + `/param/getParamTreeByChildId`, params, { noLoading: true });
};
// 根据父ID列表查询参数
export const getParamByParentIdList = (params: Dict.ReqDictParams) => {
  return http.get<Dict.ResDictList>(PORT1 + `/param/getParamByParentIdList`, params, { noLoading: true });
};

// 全部参数
export const getSearchDictList = (params: Dict.ReqDictParams) => {
  return http.post<ResPage<Dict.ResDictList>>(PORT1 + `/param/all`, params);
};

/**
 * @name 角色管理
 */

// 权限列表
// export const getListMenu = () => {
//   return http.get<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/listMenu`);
// };
//角色列表
export const listAllRole = () => {
  return http.get<ResPage<Role.ResRoleList>>(PORT1 + `/role/listAllRole`);
};

// 查询全部角色
export const getListRole = (params: Role.ReqRoleParams) => {
  return http.post<ResPage<Role.ResRoleList>>(PORT1 + `/role/pageRole`, params);
};

// 创建角色
export const createRole = (params: Dict.ReqDictParams) => {
  return http.post<ResPage<Dict.ResDictList>>(PORT1 + `/role/createRole`, params);
};

// 修改角色
export const updateRole = (params: Dict.ReqDictParams) => {
  return http.post<ResPage<Dict.ResDictList>>(PORT1 + `/role/updateRole`, params);
};

// 删除角色
export const deleteRole = (params: Dict.ReqDictParams) => {
  return http.get<ResPage<Dict.ResDictList>>(PORT1 + `/role/deleteRole`, params);
};

/**
 * @name 菜单管理
 */

// 菜单列表
export const getListMenu = () => {
  return http.get<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/listMenu`);
};
// 分页查询全部菜单
export const getPageMenu = (params: Menu.ReqMenuParams) => {
  return http.post<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/pageMenu`, params);
};

// 创建菜单
export const createMenu = (params: Menu.ReqMenuParams) => {
  return http.post<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/createMenu`, params);
};

// 删除菜单
export const deleteMenu = (params: Menu.ReqMenuParams) => {
  return http.get<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/deleteMenu`, params);
};

// 修改菜单
export const updateMenu = (params: Menu.ReqMenuParams) => {
  return http.post<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/updateMenu`, params);
};

// 根据角色id查询菜单
export const getMenuByRoleId = (params: Menu.ResMenuList) => {
  return http.get<ResPage<number[]>>(PORT1 + `/menu/getMenuByRoleId`, params);
};

// 关联角色菜单
export const insertMenuRole = (params: Menu.ReqMenuParams) => {
  return http.post<ResPage<Menu.ResMenuList>>(PORT1 + `/menu/insertMenuRole`, params);
};

/**
 * @name 用户管理
 */

// 分页查询全部菜单
export const getListUser = (params: User.ReqUserParams) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/listUser`, params);
};
// 分页查询用户积分排行榜
export const getListUserIntegral = (params: User.ReqUserParams) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/listUserIntegral`, params);
};

// 创建用户
export const createUser = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/createUser`, params);
};

// 删除菜单
export const deleteUser = (params: User.ResUserList) => {
  return http.get<ResPage<User.ResUserList>>(PORT1 + `/user/deleteUser`, params);
};

// 修改用户
export const updateUser = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/updateUser`, params);
};

// 更新密码
export const updatePassword = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/updatePassword`, params);
};
// 管理员修改密码
export const updatePasswordForAdmin = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/updatePasswordForAdmin`, params);
};
// 管理员更新用户
export const updateUserForAdmin = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/updateUserForAdmin`, params);
};
//通过用户id查询菜单
export const getMenuByUserId = (params: User.ResUserList) => {
  return http.get<ResPage<User.ResUserList>>(PORT1 + `/menu/getMenuByUserId`, params);
};
//通过用户id查询资源和资源按钮
export const getResourceByUserId = (params: Partial<User.ReqUserParams>) => {
  return http.get<ResPage<User.ResUserList>>(PORT1 + `/menu/getResourceByUserId`, params);
};
// 根据ID查询用户
export const getUserById = (params: User.ResUserList) => {
  return http.get<ResPage<User.ResUserList>>(PORT1 + `/user/getUserById`, params);
};
// 查询全部用户
export const getListAllUser = (params?: any, other?: any) => {
  return http.get<User.ResUserList[]>(PORT1 + `/user/listAllUser`, params, { ...other });
};
// 查询全部用户_根据组织树状
export const getAllUserByDepartmentTree = () => {
  return http.get<User.ResUserList[]>(PORT1 + `/user/getAllUserByDepartmentTree`);
};
// 用户资料设置

export const updateUserSetting = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/updateUserSetting`, params);
};

// 根据ID查询用户手机号
export const getMobileByUserId = (params: User.ResUserList) => {
  return http.get<User.ResUserList[]>(PORT1 + `/user/getMobileByUserId`, params);
};

// 用户注册
export const userRegister = (params: User.ResUserList) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/register`, params);
};
/**
 * @name 文件管理
 */

// 查询全部资料
export const pageDatabase = (params: File.ReqFileParams) => {
  return http.post<ResPage<File.ResFileList>>(PORT1 + `/database/pageDatabase`, params);
};

// 常用资料下载
export const databaseSort = (params: File.ReqFileParams) => {
  return http.post<ResPage<File.ResFileList>>(PORT1 + `/database/databaseSort`, params);
};

// 添加文件
export const insertDatabase = (params: File.ReqFileParams) => {
  return http.post<File.ReqFileParams>(PORT1 + `/database/insertDatabase`, params);
};

// 删除
export const deleteDatabase = (params: File.ReqFileParams) => {
  return http.get<ResPage<File.ReqFileParams>>(PORT1 + `/database/deleteDatabase`, params);
};

// 更新资料
export const updateDatabase = (params: File.ReqFileParams) => {
  return http.post<ResPage<File.ReqFileParams>>(PORT1 + `/database/updateDatabase`, params);
};
// 上传下载记录
export const downloadDatabase = (params: File.ReqFileParams) => {
  return http.get<ResPage<File.ReqFileParams>>(PORT1 + `/database/downloadDatabase`, params);
};
// 下载
export const downloadFile = (url: string) => {
  return http.download(url, {}, { baseURL: window.staticConfig.urlResource, withCredentials: false });
};

/**
 * @name 市场资料
 */

// 分页查询资料库（营销）
export const pageMarketDatabase = (params: File.ReqFileParams) => {
  return http.post<ResPage<File.ResFileList>>(PORT1 + `/database/market/page`, params);
};

// 删除
export const deleteMarketDatabase = (params: File.ReqFileParams) => {
  return http.get<ResPage<File.ReqFileParams>>(PORT1 + `/database/market/delete`, params);
};

// 添加文件
export const insertMarketDatabase = (params: File.ReqFileParams) => {
  return http.post<File.ReqFileParams>(PORT1 + `/database/market/add`, params);
};

//上传添加资料库(营销)
export const insertMarketUpload = (params: File.ReqFileParams) => {
  return http.post<File.ReqFileParams>(PORT1 + `/database/market/upload`, params);
};

// 上传下载记录
export const downloadDatabasesMarket = (params: File.ReqFileParams) => {
  return http.get<ResPage<File.ReqFileParams>>(PORT1 + `/database/market/download`, params);
};

/**
 * @name 省市区
 */

// 省
export const getProvince = (params: any) => {
  return http.get<Area>(PORT1 + `/city/getProvince`, params, { noLoading: true });
};

// 市
export const getCity = (params: Area) => {
  return http.get<Area>(PORT1 + `/city/getCity`, params, { noLoading: true });
};

// 区
export const getDistrict = (params: Area) => {
  return http.get<Area>(PORT1 + `/city/getDistrict`, params, { noLoading: true });
};

/**
 * @name 国家
 */

export const getCountryList = () => {
  return http.get<Country>(PORT1 + `/country/list`, {}, { noLoading: true });
};

/**
 * 系统管理
 */

// 查看设置
export const getSet = () => {
  return http.get<ResPage<Setting.ReqSettingParams>>(PORT1 + `/system/getSet`);
};

// 更新设置
export const updateSet = (params: Setting.ReqSettingParams) => {
  return http.post<ResPage<Setting.ReqSettingParams>>(PORT1 + `/system/updateSet`, params);
};

/**
 * @name 小课堂
 */

//  根据条件查询小课堂
export const getLessonByTerm = (params: Lesson.ReqLessonParams) => {
  return http.post<ResPage<Lesson.ResLessonList>>(PORT1 + `/lesson/getLessonByTerm`, params);
};

//发布小课堂
export const publishLesson = (params: Lesson.ReqLessonParams) => {
  return http.post<ResPage<Lesson.ReqLessonParams>>(PORT1 + `/lesson/publishLesson`, params);
};

// 更新小课堂
export const updateLesson = (params: Lesson.ReqLessonParams) => {
  return http.post<ResPage<Lesson.ReqLessonParams>>(PORT1 + `/lesson/updateLesson`, params);
};

// 删除小课堂
export const deleteLesson = (params: Question.ResQuestionList) => {
  return http.get<ResPage<Question.ResQuestionList>>(PORT1 + `/lesson/deleteLesson`, params);
};

// 根据ID查询小课堂
export const getLessonById = (params: Lesson.ReqLessonParams) => {
  return http.get<ResPage<Lesson.ResLessonList>>(PORT1 + `/lesson/getLessonById`, params);
};

/**
 * @name 提问相关
 */
//  根据条件查询提问
export const getQuestionByTerm = (params: Question.ReqQuestionParams) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/question/getQuestionByTerm`, params);
};

//发布提问
export const publishQuestion = (params: Question.ResQuestionList) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/question/publishQuestion`, params);
};

// 更新提问
export const updateQuestion = (params: Question.ResQuestionList) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/question/updateQuestion`, params);
};

// 删除提问
export const deleteQuestion = (params: Lesson.ResLessonList) => {
  return http.get<ResPage<Lesson.ResLessonList>>(PORT1 + `/question/deleteQuestion`, params);
};
// 根据ID查询提问
export const getQuestionById = (params: Question.ResQuestionList) => {
  return http.get<ResPage<Question.ResQuestionList>>(PORT1 + `/question/getQuestionById`, params);
};

// 手机端-根据条件查询提问
export const getQuestionByMobile = (params: Question.ResQuestionList) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/question/getQuestionByMobile`, params);
};

/**
 * @name 回答管理
 */
//  根据条件查询回答
export const getAnswerByQuestion = (params: Answer.ResAnswerList) => {
  return http.post<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/getAnswerByQuestion`, params);
};

//发布回答
export const publishAnswer = (params: Answer.ResAnswerList) => {
  return http.post<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/publishAnswer`, params);
};

// 更新回答
export const updateAnswer = (params: Answer.ResAnswerList) => {
  return http.post<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/updateAnswer`, params);
};

// 删除回答
export const deleteAnswer = (params: Answer.ResAnswerList) => {
  return http.get<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/deleteAnswer`, params);
};

// 根据ID查询回答
export const getAnswerById = (params: Answer.ResAnswerList) => {
  return http.get<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/getAnswerById`, params);
};

// 采纳回答
export const adoptAnswer = (params: Answer.ResAnswerList) => {
  return http.get<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/adoptAnswer`, params);
};

// 根据提问id查看是否有被采纳的回答
export const getIsAdoptByQuestion = (params: Answer.ResAnswerList) => {
  return http.get<ResPage<Answer.ResAnswerList>>(PORT1 + `/answer/getIsAdoptByQuestion`, params);
};
/**
 * @name 评审
 */
// 审核内容
export const auditContent = (params: Audit) => {
  return http.post<ResPage<Audit>>(PORT1 + `/audit/auditContent`, params);
};

/**
 * @name 评论
 */

//  根据条件查询评论
export const getCommentById = (params: Commit.ReqCommitParams) => {
  return http.post<ResPage<Commit.ResCommitList>>(PORT1 + `/comment/getCommentById`, params);
};

//发布评论
export const addComment = (params: Commit.ResCommitList) => {
  return http.post<ResPage<Commit.ResCommitList>>(PORT1 + `/comment/addComment`, params);
};
// 删除评论
export const deleteComment = (params: Commit.ReqCommitParams) => {
  return http.get<ResPage<Commit.ResCommitList>>(PORT1 + `/comment/deleteComment`, params);
};

/**
 * @name 积分管理
 */

// 查询积分规则
export const getIntegralRule = (params: Commit.ReqCommitParams) => {
  return http.get<ResPage<Commit.ResCommitList>>(PORT1 + `/integral/getIntegralRule`, params);
};

// 保存积分规则
export const saveIntegralRule = (params: Commit.ResCommitList) => {
  return http.post<ResPage<Commit.ResCommitList>>(PORT1 + `/integral/saveIntegralRule`, params);
};

//修改积分
export const updateIntegral = (params: Commit.ResCommitList) => {
  return http.post<ResPage<Commit.ResCommitList>>(PORT1 + `/integral/updateIntegral`, params);
};

//查询积分
export const pageAllIntegralDetail = (params: Commit.ResCommitList) => {
  return http.post<ResPage<Commit.ResCommitList>>(PORT1 + `/integral/pageAllIntegralDetail`, params);
};

/**
 * @name 点赞
 */

// 新增点赞
export const addLike = (params: Question.ReqQuestionParams) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/like/addLike`, params);
};

// 取消点赞
export const cancelLike = (params: Question.ReqQuestionParams) => {
  return http.post<ResPage<Question.ResQuestionList>>(PORT1 + `/like/cancelLike`, params);
};
